#!/bin/sh

set -e
pip config set global.index-url  https://pypi.tuna.tsinghua.edu.cn/simple
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone

mkdir -p /root/extensions/ttyd
cat << EOF > /root/extensions/ttyd/manifest.json
{
        "title": "远程web终端 (ttyd)",
        "description": "使用端口 5002; 用户root/ssh密码"
}
EOF

#echo "octoprint" > /root/.octoCredentials
cat << EOF > /root/extensions/ttyd/start.sh
#!/bin/sh
ttyd -p 5002 --credential root:\$(cat /root/.octoCredentials) bash
EOF

cat << EOF > /root/extensions/ttyd/kill.sh
#!/bin/sh
pkill ttyd
EOF

chmod +x /root/extensions/ttyd/start.sh
chmod +x /root/extensions/ttyd/kill.sh
chmod 777 /root/extensions/ttyd/start.sh
chmod 777 /root/extensions/ttyd/kill.sh

pip3 install -U packaging --ignore-installed -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install /root/main.zip
pip3 install --upgrade setuptools wheel tornado -i  https://pypi.tuna.tsinghua.edu.cn/simple
touch /home/print3D/.argon-fix
rm -rf  /root/main.zip
